"""
职位数据模型
"""
from django.db import models


class Position(models.Model):
    """拉勾招聘职位表"""
    
    # 原始字段
    original_id = models.IntegerField(null=True, blank=True, verbose_name='CSV中的ID')
    category = models.CharField(max_length=100, null=True, blank=True, verbose_name='职位细分类别')
    big_category = models.CharField(max_length=100, null=True, blank=True, verbose_name='职位大类')
    position_id = models.IntegerField(null=True, blank=True, verbose_name='拉勾职位ID', db_index=True)
    position_name = models.CharField(max_length=200, verbose_name='职位名称', db_index=True)
    
    # 公司信息
    company_id = models.IntegerField(null=True, blank=True, verbose_name='拉勾公司ID')
    company_full_name = models.CharField(max_length=200, null=True, blank=True, verbose_name='公司全称')
    company_size = models.CharField(max_length=50, null=True, blank=True, verbose_name='公司规模', db_index=True)
    industry_field = models.TextField(null=True, blank=True, verbose_name='行业领域')
    finance_stage = models.CharField(max_length=50, null=True, blank=True, verbose_name='融资阶段', db_index=True)
    
    # 职位信息
    position_type = models.CharField(max_length=200, null=True, blank=True, verbose_name='职位类型')
    create_time = models.DateTimeField(null=True, blank=True, verbose_name='职位发布时间')
    
    # 地点
    city = models.CharField(max_length=50, null=True, blank=True, verbose_name='城市', db_index=True)
    district = models.CharField(max_length=50, null=True, blank=True, verbose_name='区域')
    
    # 薪资（原始+解析后）
    salary = models.CharField(max_length=50, null=True, blank=True, verbose_name='薪资范围原始值')
    salary_min = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='最低薪资(k)', db_index=True)
    salary_max = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='最高薪资(k)')
    salary_avg = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='平均薪资(k)', db_index=True)
    
    # 要求
    work_year = models.CharField(max_length=50, null=True, blank=True, verbose_name='工作年限要求', db_index=True)
    job_nature = models.CharField(max_length=50, null=True, blank=True, verbose_name='工作性质')
    education = models.CharField(max_length=50, null=True, blank=True, verbose_name='学历要求', db_index=True)
    
    # 详情
    position_detail = models.TextField(null=True, blank=True, verbose_name='职位详情')
    position_advantage = models.TextField(null=True, blank=True, verbose_name='职位优势')
    
    # 时间戳
    create_at = models.DateTimeField(null=True, blank=True, verbose_name='CSV中的创建时间')
    imported_at = models.DateTimeField(auto_now_add=True, verbose_name='数据导入时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='数据更新时间')
    
    class Meta:
        db_table = 'positions'
        verbose_name = '职位信息'
        verbose_name_plural = '职位信息'
        ordering = ['-imported_at']
        indexes = [
            models.Index(fields=['category', 'city']),
            models.Index(fields=['big_category', 'salary_avg']),
        ]
    
    def __str__(self):
        return f"{self.position_name} - {self.company_full_name}"


class AIPosition(models.Model):
    """AI/大模型相关岗位表"""
    
    position_name = models.CharField(max_length=200, verbose_name='岗位名称', db_index=True)
    
    # 地点
    location = models.CharField(max_length=100, null=True, blank=True, verbose_name='工作地点原始值')
    location_city = models.CharField(max_length=50, null=True, blank=True, verbose_name='城市', db_index=True)
    location_district = models.CharField(max_length=50, null=True, blank=True, verbose_name='区域')
    
    # 薪资（原始+解析后）
    salary = models.CharField(max_length=100, null=True, blank=True, verbose_name='岗位薪资原始值')
    salary_min = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='最低薪资(k)', db_index=True)
    salary_max = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='最高薪资(k)')
    salary_avg = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='平均薪资(k)', db_index=True)
    salary_months = models.IntegerField(null=True, blank=True, verbose_name='薪资月数')
    
    # 要求
    experience = models.CharField(max_length=50, null=True, blank=True, verbose_name='经验要求', db_index=True)
    education = models.CharField(max_length=50, null=True, blank=True, verbose_name='学历要求', db_index=True)
    education_normalized = models.CharField(max_length=20, null=True, blank=True, verbose_name='规范化学历')
    
    # 标签
    tags = models.TextField(null=True, blank=True, verbose_name='岗位标签')
    
    # 企业信息
    company_name = models.CharField(max_length=200, null=True, blank=True, verbose_name='企业名称')
    company_industry = models.CharField(max_length=100, null=True, blank=True, verbose_name='企业行业')
    company_scale = models.CharField(max_length=50, null=True, blank=True, verbose_name='企业规模', db_index=True)
    financing_status = models.CharField(max_length=50, null=True, blank=True, verbose_name='融资状况')
    
    # 时间戳
    imported_at = models.DateTimeField(auto_now_add=True, verbose_name='数据导入时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='数据更新时间')
    
    class Meta:
        db_table = 'ai_positions'
        verbose_name = 'AI岗位信息'
        verbose_name_plural = 'AI岗位信息'
        ordering = ['-imported_at']
        indexes = [
            models.Index(fields=['location_city', 'salary_avg']),
        ]
    
    def __str__(self):
        return f"{self.position_name} - {self.company_name}"

